package com.zsr.utils;

import org.apache.commons.beanutils.BeanUtils;


import java.util.Map;

public class WebUtils {
    /**
     * 将Map注入bean
     *
     * @param value Map
     * @param bean
     */
    public static <T> T copyParamToBean(Map value, T bean) {

        try {
            System.out.println("注入之前：" + bean);
            BeanUtils.populate(bean, value);
            System.out.println("注入之后：" + bean);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bean;
    }


    /***
     * 字符串转为Int
     * @param strInt 字符串
     * @param defaultValue 异常时默认值
     * @return
     */
    public static int parseInt(String strInt, int defaultValue) {

        if(strInt==null)return defaultValue;
        try {
            return Integer.parseInt(strInt);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  defaultValue;
    }


}
